{extend name="base" /}
{block name="body"}
<div class="admin-main">
<div class="layui-field-box layui-form">
				<a href="{:url('admin/ForumForum/add')}" class="layui-btn layui-btn-sm" id="add">
					<i class="layui-icon">&#xe608;</i> 添加板块
				</a>
<table class="layui-table admin-table">
	<thead>
					<tr>
<th width="5%" align="center">ID</th>
<th width="20%" align="center">板块名称</th>
<th width="10%" align="center">是否显示</th>
<th width="10%" align="center">排序</th>
<th width="10%" align="center">添加时间</th>
<th width="10%" align="center">基本操作</th>
</tr>
   </thead>
					<tbody>
{volist name="list" id="vo"}
<tr>
<td align="center">{$vo.forum_id}</td>
<td style="padding-left: 20px;">{$vo.forum_name}</td>

<td align="center">

<input type="checkbox" name="is_show" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchshow"  value="{$vo['forum_id']}" {php}echo $vo['is_show']==1 ? 'checked' : '';{/php}>
</td>
<td width="10%">
	<input width="10%" type="text" name="sort_order" autocomplete="off" lay-verify="" placeholder="请输入排序数值" value="{$vo.sort_order}" data-sort="{$vo.sort_order}" data-id="{$vo.forum_id}" class="layui-input">
</td>
<td align="center">{$vo.add_time|date="Y-m-d"}</td>
<td align="center">
<a class="layui-btn layui-btn-normal layui-btn-xs" style="font-size: 14px;" href="{:url('ForumForum/edit',array('forum_id'=>$vo['forum_id']))}">修改</a>
<a href="javascript:;" data-id="{$vo.forum_id}" data-url="{:url('admin/ForumForum/delete',array('forum_id'=>$vo['forum_id']))}" data-opt="del"  class="elementdel layui-btn layui-btn-danger layui-btn-xs ajax-delete" style="font-size: 14px;">删除</a>

</td>
</tr>
{/volist}
  </tbody>
</table>
	</div>
		
			
		</div>				
{/block}
{block name="page"}
<div class="btable-paged">
	<div class="layui-main">
		{$list->render()|raw}
	</div>
</div>
{/block}
	{block name="js"}
<script type="text/javascript" src="__PUBLIC__/js/delelement.js"></script>
 {/block}
	{block name="script"}
	<script>
layui.use(['form'],function(){
  var form = layui.form
  ,jq = layui.jquery;


 //jq('.btable-paged').eq(1).hide();
 var status=0;
 form.on('switch(switchTest)', function(data){
	  loading = layer.load(2, {
		  shade: [0.2,'#000']
		});
		if(data.elem.checked){
			status=1;
		}else{
			status=0;
		}
		var url="{:url('admin/forumcate/updatestatus')}?id="+data.value+'&status='+status+'&name=sidebar' ;
	   
		
		jq.get(url,function(data){
			
		  if(data.code == 200){
			layer.close(loading);
			layer.msg(data.msg, {icon: 1, time: 1000}, function(){
			//  location.reload();
			});
		  }else{
			layer.close(loading);
			layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
		  }
		});
		return false;
	  });
 var status=0;
 form.on('switch(switchshow)', function(data){
	  loading = layer.load(2, {
		  shade: [0.2,'#000']
		});
		if(data.elem.checked){
			status=1;
		}else{
			status=0;
		}
		var url="{:url('admin/ForumForum/updatestatus')}?id="+data.value+'&status='+status+'&name=is_show' ;
	   
		
		jq.get(url,function(data){
			
		  if(data.code == 200){
			layer.close(loading);
			layer.msg(data.msg, {icon: 1, time: 1000}, function(){
			//  location.reload();
			});
		  }else{
			layer.close(loading);
			layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
		  }
		});
		return false;
	  });

	jq("input[name='sort_order']").blur(function () {
		console.log('sort.blur');
		let sort = jq(this).data('sort');
		let id = jq(this).data('id');
		let value = jq(this).val();
		console.log('sort: ', sort)
		if (value == '') {
			jq(this).val(sort);
			return false;
		}
		if (sort == value) return false;
		let param = {
			id: id,
			name: 'sort_order',
			status: value
		}
		let that = jq(this);
		console.log(param);
		jq.get('updatestatus', param, function (res) {
			if (res.code == 200) {
				console.log('200');
				that.data('sort', value);
			} else {

			}
			layer.msg(res.msg);
		});
	});

})
</script>
 {/block}



